﻿// Copyright (c) 2025 liucl
// Inject is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan
// PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

#include "sub_wnd.hpp"
#include "log_sink.hpp"

#include <format>

void SubWin::OnChar(TCHAR chChar, UINT nRepCnt, UINT nFlags) {
  SetMsgHandled(false);
  std::string str =
      std::format("OnChar: chChar: {}, nRepCnt: {}, nFlags: {}:ATL:{}",
                  static_cast<char>(chChar), nRepCnt, nFlags,
                  (nFlags & 16384) ? true : false);
  LogUDPSink::send_package(str.data(), str.size());

  return;
}

void SubWin::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {
  SetMsgHandled(false);

  char buffer[100] = {0};
  GetWindowTextA(this->m_hWnd, buffer, 100);
  std::string str =
      std::format("OnKeyDown: nChar: {}, nRepCnt: {}, nFlags: {} text:{}",
                  (char)nChar, nRepCnt, nFlags, buffer);
  LogUDPSink::send_package(str.data(), str.size());

  return;
}

void SubWin::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) {
  SetMsgHandled(false);
  char buffer[100] = {0};
  GetWindowTextA(this->m_hWnd, buffer, 100);
  std::string str =
      std::format("OnKeyUp: nChar: {}, nRepCnt: {}, nFlags: {} text:{}",
                  (char)nChar, nRepCnt, nFlags, buffer);
  LogUDPSink::send_package(str.data(), str.size());
  return;
}